import Vue from './vue/main.js'

window.onload = function (){
    var app = new Vue({
        el: '#app',
        data: {
            msg: '你好aaaaddd',
            obj: {
                name: '李焕英',
                age: 18
            },
            arr: [1,2, {value: 3}]
        },
        watch: {
            msg: function(now, old){
                console.log('watcher:', now, ', oldWatcher: ',old)
            },
            'obj.name' : function(now, old){
                console.log('watcher:', now, ', oldWatcher: ',old)
            }
        }
    })

    window.a = app

    var btn = document.getElementById('btn')
    btn.onclick = function(){
        app.obj.name = 'adasd' + Math.floor(Math.random()*10000)
        app.msg = document.getElementById('msg').value
        app.$nextTick(()=>{
            console.log('数据修改完毕')
        })
    }

    function commSort(arr, ...arg){

        let expre= []

        if(arg.length === 1){
            expre = [`a.${arg[0]} - b.${arg[0]}`]
        }else{
            let l = arg.length
            let temp = arg.concat(arg.slice(0,arg.length-1).reverse())
            let tl = temp.length - 1
            expre = temp.reduce((p, item, i ) => {
                return p = i < l - 1 ?
                        p.concat(`a.${item} - b.${item} === 0 ?`):
                        i <tl ?
                        p.concat(`a.${item} - b.${item} :`):
                        p.concat(`a.${item} - b.${item}`)
            },[])
        }
        arr.sort((a,b)=>
            eval(expre.join('\n')))
    }

    window.commSort = commSort
}
